package org.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.seata.spring.annotation.GlobalTransactional;
import org.example.domain.UserDomain;
import org.example.mapper.UserMapper;
import org.example.model.User;
import org.example.service.UserService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {


    @Override
    public UserDomain selectUserById(Integer id) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", id);
        User user = baseMapper.selectOne(queryWrapper);
        UserDomain userDomain = new UserDomain();
        BeanUtils.copyProperties(user, userDomain);
        return userDomain;
    }

    @Override
    @GlobalTransactional
    public Boolean insertUser(UserDomain user) {
        User realUser = new User();
        BeanUtils.copyProperties(user, realUser);
        baseMapper.insert(realUser);
        return true;
    }
}
